package com.ssm.zyn.service.impl;

import com.ssm.zyn.dao.ExamineTestMapper;
import com.ssm.zyn.eo.ExamineTestEOpage;
import com.ssm.zyn.model.ExamineTest;
import com.ssm.zyn.service.ExamineTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * 实现业务及流程接口当中的内容
 */
@Service
public class ExamineTestServiceImpl implements ExamineTestService {
    @Autowired
    private ExamineTestMapper examineTestMapper;
    /**
     *
     * @param examineTest
     * @return
     */
    @Override
    public int AddExamineTest(ExamineTest examineTest) {
        int returnInt = 0;
        /**1.业务的判断
         * (1)角色名称不能重复
         */
        //(1)判断角色
        int testNameCount = examineTestMapper.getTestNameCount(examineTest.getTestname());
        if (testNameCount < 1) {
            //2.数据的添加
            int addRoleInt = examineTestMapper.insertExamineTest(examineTest);
            //3.返回值的设置
            returnInt = addRoleInt;
        } else {
            returnInt = -1;//有相同的角色名称
        }

        return returnInt;
    }

    /**
     *
     * @param examineTest
     * @return
     */

    @Override
    public int UpdateExamineTest(ExamineTest examineTest) {
        int isUpdate = 0;

        int testNameCount = examineTestMapper.getTestNameCount(examineTest.getTestname());
        /*1.没有相关业务流程的判断*/
        try {
            if (testNameCount<1){
            isUpdate = examineTestMapper.updateExaminetest(examineTest);}
        } catch (Exception e) {
            isUpdate = -1;
            //打印更新时报错的情况
            System.out.println("更新角色信息时执行SQL报错的原因为"+e.getMessage());
        }
        return isUpdate;
    }

    /**
     *
     * @param testid
     * @return
     */
    @Override
    public int DeleteExamineTest(int testid) {
        int delExamineTest=0;
        try{
            delExamineTest=examineTestMapper.delExamineTest(testid);
        }catch (Exception e){
            delExamineTest=-1;
            System.out.println("删除班级信息时执行SQL报错，信息为"+e.getMessage());
        }
        return delExamineTest;
    }

    /**
     *
     * @param examineTestEOpage
     * @return
     */
    @Override
    public List<ExamineTestEOpage> getWhereAll(ExamineTestEOpage examineTestEOpage) {
        List<ExamineTestEOpage> listExamineTest= examineTestMapper.getWhereAll(examineTestEOpage);
        return listExamineTest;
    }
}
